import request from "../../../utils/request.ts";
import {T_MenuParams, T_PermissionResponseData} from "./type.ts";

enum API {
    //获取全部菜单与按钮的标识数据
    ALLPERMISSION_URL = "/admin/acl/permission",
    //给定某一级菜单新增一个子菜单
    ADDMENU_URL = "/admin/acl/permission/save",
    //更新某一个已有的菜单
    UPDATE_URL = "/admin/acl/permission/update",
    //根据id删除菜单的接口
    DELETEMENU_URL = "/admin/acl/permission/remove/"

}

//获取菜单数据
export const reqAllPermission = () => request.get<any, T_PermissionResponseData>(API.ALLPERMISSION_URL)

//添加与更新菜单的方法
export const reqAddOrUpdateMenu = (data: T_MenuParams) => {
    if (data.id) {
        //更新
        return request.put<any, any>(API.UPDATE_URL, data);
    } else {
        //新增
        return request.post<any, any>(API.ADDMENU_URL, data);
    }
}

//删除某一个已有菜单
export const reqRemoveMenu = (id: number) => request.delete<any, any>(API.DELETEMENU_URL + id);